package com.example.projectmanagement.repository;

import com.example.projectmanagement.model.RolePermission;
import com.example.projectmanagement.model.Role;
import com.example.projectmanagement.model.Permission;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.List;

@Repository
public interface RolePermissionRepository extends JpaRepository<RolePermission, Long> {
    List<RolePermission> findByRole(Role role);
    List<RolePermission> findByRole_Id(Long roleId);
    
    @Query("SELECT rp.permission FROM RolePermission rp WHERE rp.role.id = :roleId")
    List<Permission> findPermissionsByRoleId(@Param("roleId") Long roleId);
    
    void deleteByRole_Id(Long roleId);
    
    void deleteByRole_IdAndPermission_Id(Long roleId, Long permissionId);
}